/**
 * 3
 *  
 * @Author : roryrywang
 * @DateTime : 24-8-24 下午1:32
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int sum = 0;
    int cnt = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '?')cnt++;
        else sum += s[i] - '0';
    }

    long long f[cnt + 1][3];
    for (int i = 0; i < 3; ++i) {
        if (i == sum % 3)f[0][i] = 1;
        else f[0][i] = 0;
    }

    for (int i = 1; i <= cnt; ++i) {
        f[i][0] = (4 * f[i - 1][0] + 3 * f[i - 1][1] + 3 * f[i - 1][2]) % MOD;
        f[i][1] = (3 * f[i - 1][0] + 4 * f[i - 1][1] + 3 * f[i - 1][2]) % MOD;
        f[i][2] = (3 * f[i - 1][0] + 3 * f[i - 1][1] + 4 * f[i - 1][2]) % MOD;
    }

    long long res = f[cnt][0];
    // 去重首位为0的情况
    if (s[0] == '?') res = (res + MOD - f[cnt - 1][0]) % MOD;
    cout << res;
    return 0;
}